package com.example.demo.controller;

import com.example.demo.pojo.vo.LoginVo;
import com.example.demo.service.UserService;
import com.example.demo.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 程序员小洋
 * @version 2022.3
 * @date 2023/5/9 09:36
 * @title 登录控制器
 */
@SuppressWarnings("all")
@RestController
@Api(tags = "登录控制器")
@CrossOrigin

public class LoginController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     * @param loginVo
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("登录")
    public Result login(@RequestBody LoginVo loginVo){
        LoginVo db = userService.login(loginVo);
        if (db != null){
            if (!(db.getPassword().equals(loginVo.getPassword()))){
                return Result.error("账号或密码错误");
            }
        }else {
            return Result.error("用户名不存在");
        }
        return Result.success(db);
    }
}
